import axios from "axios";
import Iemoticon from "@/interface/emoticon/Iemoticon";
import IEmoticonParam from "@/interface/emoticon/IEmoticonParam";

//https://yanwenzi.fuhaoku.net/
async function getEmoticon(): Promise<Array<Iemoticon>> {
  //获取颜文字
  const emoticonList: Array<Iemoticon> = [];
  try {
    const res = await axios.get("http://119.91.81.28:1337/emoticons");

    const data: Array<IEmoticonParam> = res.data;

    const map = new Map();

    data.map((item: IEmoticonParam) => {
      if (map.has(item.type)) {
        const arr = map.get(item.type);
        map.set(item.type, [
          ...arr,
          {
            id: item.id,
            name: item.name,
            description: item.description,
          },
        ]);
      } else {
        map.set(item.type, [
          {
            id: item.id,
            name: item.name,
            description: item.description,
          },
        ]);
      }
    });

    for (const [key, value] of map.entries()) {
      emoticonList.push({
        type: key,
        list: value,
      });
    }
  } catch (error) {
    console.log("获取颜文字接口错误", error);
  }

  return emoticonList;
}

export default getEmoticon;
